﻿namespace PMS.Client.FrmUserType
{
    using AdvancedDataGridView;
    using PMS.BLL;
    using PMS.Model;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class FrmSelect : Form
    {
        private UserTypeBLL bll = new UserTypeBLL();
        private Button btnCancel;
        private Button btnOK;
        private IContainer components = null;
        private GroupBox groupBox1;
        private DataGridViewTextBoxColumn IsLeader;
        private Label label1;
        private TreeGridNode node1 = null;
        private TreeGridNode node2 = null;
        private TreeGridView treeGridView1;
        private TextBox txtSelect;
        private DataGridViewTextBoxColumn typeID;
        private TreeGridColumn typeName;

        public FrmSelect()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if ((this.treeGridView1.SelectedRows.Count > 0) && (this.treeGridView1.SelectedRows[0].Cells["typeID"].Value != null))
            {
                this.UserType = this.treeGridView1.SelectedRows[0].Cells["typeName"].Value.ToString();
                base.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("请选择！");
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FrmSelect_Load(object sender, EventArgs e)
        {
            Font font = new Font(this.treeGridView1.DefaultCellStyle.Font, FontStyle.Bold);
            object[] values = new object[3];
            values[0] = "领导人";
            this.node1 = this.treeGridView1.Nodes.Add(values);
            this.node1.DefaultCellStyle.BackColor = SystemColors.Highlight;
            this.node1.DefaultCellStyle.ForeColor = Color.White;
            this.node1.DefaultCellStyle.Font = font;
            this.node1.Expand();
            values = new object[3];
            values[0] = "非领导人";
            this.node2 = this.treeGridView1.Nodes.Add(values);
            this.node2.DefaultCellStyle.BackColor = SystemColors.Highlight;
            this.node2.DefaultCellStyle.ForeColor = Color.White;
            this.node2.DefaultCellStyle.Font = font;
            this.node2.Expand();
            this.LoadUserType();
        }

        private void InitializeComponent()
        {
            this.treeGridView1 = new TreeGridView();
            this.btnCancel = new Button();
            this.btnOK = new Button();
            this.groupBox1 = new GroupBox();
            this.txtSelect = new TextBox();
            this.label1 = new Label();
            this.typeName = new TreeGridColumn();
            this.typeID = new DataGridViewTextBoxColumn();
            this.IsLeader = new DataGridViewTextBoxColumn();
            ((ISupportInitialize) this.treeGridView1).BeginInit();
            this.groupBox1.SuspendLayout();
            base.SuspendLayout();
            this.treeGridView1.AllowUserToAddRows = false;
            this.treeGridView1.AllowUserToDeleteRows = false;
            this.treeGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            this.treeGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            this.treeGridView1.BackgroundColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            this.treeGridView1.BorderStyle = BorderStyle.None;
            this.treeGridView1.Columns.AddRange(new DataGridViewColumn[] { this.typeName, this.typeID, this.IsLeader });
            this.treeGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
            this.treeGridView1.EnableHeadersVisualStyles = false;
            this.treeGridView1.ImageList = null;
            this.treeGridView1.Location = new Point(2, 2);
            this.treeGridView1.MultiSelect = false;
            this.treeGridView1.Name = "treeGridView1";
            this.treeGridView1.RowHeadersVisible = false;
            this.treeGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            this.treeGridView1.Size = new Size(330, 0x13a);
            this.treeGridView1.TabIndex = 6;
            this.treeGridView1.SelectionChanged += new EventHandler(this.treeGridView1_SelectionChanged);
            this.treeGridView1.DoubleClick += new EventHandler(this.treeGridView1_DoubleClick);
            this.btnCancel.BackColor = Color.White;
            this.btnCancel.FlatStyle = FlatStyle.Popup;
            this.btnCancel.Location = new Point(0xd0, 0x17e);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 12;
            this.btnCancel.Text = "关闭";
            this.btnCancel.UseVisualStyleBackColor = false;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnOK.BackColor = Color.White;
            this.btnOK.FlatStyle = FlatStyle.Popup;
            this.btnOK.Location = new Point(0x55, 0x17e);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new Size(0x4b, 0x17);
            this.btnOK.TabIndex = 11;
            this.btnOK.Text = "确定";
            this.btnOK.UseVisualStyleBackColor = false;
            this.btnOK.Click += new EventHandler(this.btnOK_Click);
            this.groupBox1.Controls.Add(this.txtSelect);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new Point(2, 0x142);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(330, 0x31);
            this.groupBox1.TabIndex = 10;
            this.groupBox1.TabStop = false;
            this.txtSelect.BackColor = Color.FromArgb(0xd9, 0xea, 0xf7);
            this.txtSelect.BorderStyle = BorderStyle.FixedSingle;
            this.txtSelect.Location = new Point(0x53, 20);
            this.txtSelect.Name = "txtSelect";
            this.txtSelect.Size = new Size(0xc6, 0x15);
            this.txtSelect.TabIndex = 50;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(12, 0x16);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x41, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "您选择的是";
            this.typeName.DefaultNodeImage = null;
            this.typeName.HeaderText = "人员分类";
            this.typeName.Name = "typeName";
            this.typeName.Resizable = DataGridViewTriState.True;
            this.typeName.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.typeID.HeaderText = "typeID";
            this.typeID.Name = "typeID";
            this.typeID.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.typeID.Visible = false;
            this.IsLeader.HeaderText = "IsLeader";
            this.IsLeader.Name = "IsLeader";
            this.IsLeader.SortMode = DataGridViewColumnSortMode.NotSortable;
            this.IsLeader.Visible = false;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackColor = Color.FromArgb(0xa4, 0xc4, 0xeb);
            base.ClientSize = new Size(0x14e, 0x19b);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOK);
            base.Controls.Add(this.groupBox1);
            base.Controls.Add(this.treeGridView1);
            base.Name = "FrmSelect";
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "选择人员分类";
            base.Load += new EventHandler(this.FrmSelect_Load);
            ((ISupportInitialize) this.treeGridView1).EndInit();
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void LoadUserType()
        {
            this.node1.Nodes.Clear();
            this.node2.Nodes.Clear();
            List<PMS.Model.UserType> list = this.bll.GetList();
            foreach (PMS.Model.UserType type in list)
            {
                if (type.IsLeader == 1)
                {
                    this.node1.Nodes.Add(new object[] { type.TypeName, type.TypeID, type.IsLeader });
                }
                else
                {
                    this.node2.Nodes.Add(new object[] { type.TypeName, type.TypeID, type.IsLeader });
                }
            }
        }

        private void treeGridView1_DoubleClick(object sender, EventArgs e)
        {
            if ((this.treeGridView1.SelectedRows.Count > 0) && (this.treeGridView1.SelectedRows[0].Cells["typeID"].Value != null))
            {
                this.UserType = this.treeGridView1.SelectedRows[0].Cells["typeName"].Value.ToString();
                base.DialogResult = DialogResult.OK;
            }
        }

        private void treeGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if ((this.treeGridView1.SelectedRows.Count > 0) && (this.treeGridView1.SelectedRows[0].Cells["typeID"].Value != null))
            {
                this.txtSelect.Text = this.treeGridView1.SelectedRows[0].Cells["typeName"].Value.ToString();
            }
        }

        public string UserType { get; set; }
    }
}

